package com.fish.admin.module.system.controller;

import com.fish.admin.module.system.enums.SubjectTypeEnum;
import com.fish.admin.module.system.service.SysAuthorityService;
import com.fish.common.core.base.Router;
import com.fish.common.core.response.RestResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/menu")
@Slf4j
public class SysMenuController {

    private final SysAuthorityService sysAuthorityService;
    /**
     * 用户的路由
     * @return
     */
    @GetMapping("/v1/me")
    public RestResponse<List<Router>> tree() {
        return RestResponse.ok(sysAuthorityService.authorization().getMenus());
    }
    /**
     * 根据角色授权
     * @param roleId
     * @return
     */
    @GetMapping("/v1/authorize/role/{roleId}")
    public RestResponse<List<Long>> roleAuthorize(@PathVariable Long roleId) {
        return RestResponse.ok(sysAuthorityService.authorize(roleId, SubjectTypeEnum.ROLE));
    }
}
